/*
    backend for TimeTagger, an OpalKelly based single photon counting library
    Copyright (C) 2011  Markus Wick <wickmarkus@web.de>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef BACKEND_ITERATOR_H_
#define BACKEND_ITERATOR_H_

#include <queue>
#include <fstream>

#include "TimeTagger.h"
#include "Thread.h"

class Iterator : public _Iterator {
public:
	Iterator(int chan);
	virtual ~Iterator();

	virtual const char *getClassName();
	virtual const char *getScpiCommand();
	virtual std::string getScpiParameters();
	virtual void getMeta(long long **ARGOUTVIEWM_ARRAY2, int *DIM1);

	Iterator* __iter__();

	long long next();
	int size();
	virtual void clear();

protected:
	virtual void next(Tag* list, int count, long long time);

private:
	std::queue<long long> q;
	int channel;
};


class OverFlow : public _Iterator {
public:
	OverFlow();
	virtual ~OverFlow();

	virtual const char *getClassName();
	virtual const char *getScpiCommand();
	virtual std::string getScpiParameters();
	virtual void getMeta(long long **ARGOUTVIEWM_ARRAY2, int *DIM1);

	virtual void clear();
	long long overflows;

protected:
	virtual void next(Tag* list, int count, long long time);

private:
	long long show_next;
};


class Dump : public _Iterator {
public:
	Dump(std::string _filename);
	~Dump();

	virtual const char *getClassName();
	virtual const char *getScpiCommand();
	virtual std::string getScpiParameters();
	virtual void getMeta(long long **ARGOUTVIEWM_ARRAY2, int *DIM1);

	virtual void clear();

protected:
	virtual void next(Tag* list, int count, long long time);

private:
	std::ofstream *output_file;
	std::string filename;
};


class Chans : public _Iterator {
public:
	Chans();
	virtual ~Chans();

	virtual const char *getClassName();
	virtual const char *getScpiCommand();
	virtual std::string getScpiParameters();
	virtual void getMeta(long long **ARGOUTVIEWM_ARRAY2, int *DIM1);

	void registerChannel(int chan);
	void unregisterChannel(int chan);

	virtual void clear();

protected:
	virtual void next(Tag* list, int count, long long time);
};

#endif /* ITERATOR_H_ */
